package org.lztvn.elearning.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.lztvn.elearning.entities.Product;
import org.lztvn.elearning.entities.StudentTest;

public class StudentTestDaoImpl implements IStudentTestDao{
	@PersistenceContext
	private EntityManager em;
	@Override
	public Long addStudentTest(StudentTest s) {
		em.persist(s);
		return s.getIdStudentTest();
	}

	@Override
	public void deleteStudentTest(Long idSt) {
		StudentTest s = em.find(StudentTest.class, idSt);
		em.remove(s);
		
	}

	@Override
	public void modifierStudentTest(StudentTest s) {
		em.merge(s);
	}

	@Override
	public List<StudentTest> listStudentTestByStudentId(Long idStudent) {
		Query req = em.createQuery("select s from StudentTest s where s.idUser = :x");
		req.setParameter("x",idStudent);
		return  req.getResultList();
	}

	@Override
	public List<StudentTest> listStudentTestByTestId(Long idTest) {
		Query req = em.createQuery("select s from StudentTest s where s.mytest.id = :x");
		req.setParameter("x",idTest);
		return  req.getResultList();
	}

	@Override
	public StudentTest getStudentTest(Long idSt) {
		return em.find(StudentTest.class, idSt);
	}

	@Override
	public Long getNbStudentTestByUserId(Long idStudent) {
		// TODO Auto-generated method stub
		return null;
	}

}
